package health.lm.com.order.model;

import org.json.JSONObject;

import health.lm.com.component_base.pay.PaymentEntity;
import health.lm.com.data.App;
import health.lm.com.data.HttpCST;
import health.lm.com.network.EasyHttp;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.network.utils.MyApi;
import health.lm.com.order.entity.ActivityPayEntity;
import health.lm.com.order.entity.OrderListEntity;
import health.lm.com.order.entity.PayResultEntity;
import health.lm.com.order.entity.RecordListEntity;
import health.lm.com.order.entity.SweepPayCoinEntity;
import health.lm.com.order.entity.SweepPayEntity;

/**
 * @description 订单模块
 * @author GQI
 * @date :2019-08-16 10:38
 */
public class OrderModel {
    private static OrderModel model;

    public static OrderModel getInstance() {
        if (null == model) {
            model = new OrderModel();
        }
        return model;
    }

    /**
     * 会员订单列表
     *
     * @param observer observer
     */
    public void recordList(String is_evaluate, int page, int pageSize, SimpleCallBack<RecordListEntity> observer) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put("is_evaluate", is_evaluate);
            jsonObject.put(HttpCST.PAGE_SIZE, pageSize);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_ORDER, HttpCST.INTFC_1001, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(observer);
    }
    /**
     * 联盟商订单列表
     *
     * @param observer observer
     */
    public void orderList( int page, int pageSize, SimpleCallBack<OrderListEntity> observer) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put(HttpCST.PAGE_SIZE, pageSize);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_ORDER, HttpCST.INTFC_1002, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(observer);
    }
    /**
     * 激活
     * @param observer observer
     */
    public void activation( String activate_fee, int pay_type, SimpleCallBack<PaymentEntity> observer) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("activate_fee", activate_fee);
            jsonObject.put("pay_type", pay_type);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1014, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(observer);
    }
    /**
     * 活动支付页面
     * @param observer observer
     */
    public void activityInfo( String active_id,SimpleCallBack<ActivityPayEntity> observer) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("active_id", active_id);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_ACTIVE, HttpCST.INTFC_1010, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(observer);
    }
    /**
     * 参与活动支付
     * @param observer observer
     */
    public void activity( String active_id, int pay_type, String coin,SimpleCallBack<PaymentEntity> observer) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("active_id", active_id);
            jsonObject.put("order_type", 2);
            jsonObject.put("pay_type", pay_type);
            jsonObject.put("coin", coin);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_ACTIVE, HttpCST.INTFC_1003, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(observer);
    }
    /**
     * 线下支付详情页
     * @param observer observer
     */
    public void sweepPayInfo( String union_id,SimpleCallBack<SweepPayEntity> observer) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("union_id", union_id);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_UNION, HttpCST.INTFC_1009, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(observer);
    }
    /**
     * h链优惠
     * @param observer observer
     */
    public void sweepHcoin( String union_id,String money, SimpleCallBack<SweepPayCoinEntity> observer) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("union_id", union_id);
            jsonObject.put("money", money);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_UNION, HttpCST.INTFC_1010, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(observer);
    }
    /**
     * 线下支付
     * @param observer observer
     */
    public void sweepPay( String union_id, int pay_type, String all_money,String is_use_coin,SimpleCallBack<PaymentEntity> observer) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("union_id", union_id);
            jsonObject.put("order_type", 2);
            jsonObject.put("pay_type", pay_type);
            jsonObject.put("is_use_coin", is_use_coin);
            jsonObject.put("all_money", all_money);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_UNION, HttpCST.INTFC_1005, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(observer);
    }
    /**
     * 查询支付状态
     * @param observer observer
     */
    public void checkPayState( String order_sn, int pay_type, SimpleCallBack<PayResultEntity> observer) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("order_sn", order_sn);
            jsonObject.put("pay_type", pay_type);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_UTILS, HttpCST.INTFC_1003, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(observer);
    }
}